package dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;

import connectUtil.ConnectionUtil;
import entity.Visitor;

public class Search {
	private static Connection conn;
    private static CallableStatement callProc;
    private static ResultSet rs;
	public static ArrayList<Visitor> searchName(String name){
		ArrayList<Visitor> list = new ArrayList<Visitor>();
		Visitor e = null;
		try{
			conn = ConnectionUtil.getConnection();
    		callProc = conn.prepareCall("{call SearchName(?)}");
    		callProc.setString(1,name);
    		rs = callProc.executeQuery();
    		//System.out.println(" 1");
    		String firstName, lastName, gender, telephone, area, hobby, des;
    		while(rs.next()){
    			e = new Visitor();
    			firstName = rs.getString(1);
    			lastName = rs.getString(2);
    			gender = rs.getString(3);
    			telephone = rs.getString(4);
    			area = rs.getString(5);
    			hobby = rs.getString(6);
    			des = rs.getString(7);
    			e.setFirstName(firstName);
    			e.setLastName(lastName);
    			e.setGender(gender);
    			e.setTelephone(telephone);
    			e.setArea(area);
    			e.setHobby(hobby);
    			e.setDescription(des);
    			list.add(e);
    		}
		}catch(Exception ex){
			System.out.println(ex.getMessage());
		}
		System.out.println(" so luong visitor tim duoc: " + list.size());
		return list;
	}
//    public static void main( String[] args) {
//    	ArrayList<Visitor> list = searchName("h");
//	}
}
